from django.db import models
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill


class Navbar(models.Model):
    title = models.CharField('标题',max_length=128)
    url = models.URLField(blank=True, verbose_name="链接")
    avatar_thumbnail = ProcessedImageField(
        upload_to = 'navbar/%Y%m%d',
        processors = [ResizeToFill(320,200)],
        format = 'JPEG',
        options = {'quality': 100},
        blank = True,
        null = True,
        verbose_name = "缩略图",
    )


    def __str__(self):
        return self.title

class Category(models.Model):
    name = models.CharField("分类",max_length=64)

    def __str__(self):
        return self.name

film_type = (('2D',"2D"),
             ('3D','3D'),)

actor_role = (('director','导演'),
              ('actor',"演员"))

class Actors(models.Model):

    name = models.CharField("姓名", max_length=32)
    movie_name = models.ForeignKey(to='Movie',verbose_name="剧名",on_delete=models.CASCADE)
    role = models.CharField('角色',max_length=32,choices=actor_role)
    img = models.URLField(verbose_name="图片链接",blank=True)

    def __str__(self):
        return "%s--%s--%s"%(self.name,self.get_role_display(),self.movie_name.name,)

or_show = (('1','未上映'),
           ('2','已上映'),
           ('3','已下线'),
           )

class Movie(models.Model):
    filmId = models.AutoField(primary_key=True)
    name = models.CharField("名称",max_length=64)
    grade = models.DecimalField(verbose_name="评分",max_digits=3,decimal_places=1,default=0)
    actor = models.ForeignKey(to='self',verbose_name="演员",blank=True,null=True,on_delete=models.DO_NOTHING,related_name="actor_list")
    nation = models.CharField("地区",max_length=64)
    runtime = models.DecimalField(verbose_name="时长",max_digits=4,decimal_places=0,blank=True)
    poster = models.URLField(blank=True,verbose_name="图片链接")
    filmtype = models.CharField("影片类型",choices=film_type,max_length=16,default='2D')
    photos = models.ForeignKey(to='self', verbose_name="剧照", blank=True, null=True, on_delete=models.DO_NOTHING)
    category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name="分类",blank=True,default=1)
    excerpt = models.CharField("简介", max_length=256, blank=True)
    isShow = models.CharField("是否上映",max_length=32,choices=or_show,default=1)

    def __str__(self):
        return self.name



class StagePhoto(models.Model):
    movie = models.ForeignKey(Movie,verbose_name="剧名",on_delete=models.CASCADE)
    img = models.URLField(verbose_name="剧照链接",blank=True)

    def __str__(self):
        return "%s--%s"%(self.movie.name,self.id)


class ComingShow(Movie):
    show_date = models.DateTimeField(verbose_name="上映日期")


    def __str__(self):
        return "%s--%s"%("即将上映",self.name)




